/*
 * Copyright (c) 2017. 深圳一七科技. All rights reserved.
 */

package com.yiqi.liebang.feature.home.presenter;

import com.amap.api.maps2d.MapView;
import com.suozhang.framework.entity.bo.UserInfoBo;
import com.yiqi.liebang.entity.bo.HomeBo;
import com.yiqi.liebang.feature.home.contract.HomeContract;
import com.yiqi.liebang.feature.home.dependencies.home.DaggerHomePresenterComponent;

import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

import javax.inject.Inject;

/**
 * LIJUWEN
 *
 * @email yiyayiyayaoljw@gmail.com
 * @date 2018/7/11 9:31
 */
public class HomePresenter implements HomeContract.Presenter {

    private HomeContract.View mView;

    @Inject

    HomeContract.Model mModel;


    public HomePresenter(HomeContract.View mView) {
        this.mView = mView;
        DaggerHomePresenterComponent.create().inject(this);
    }

    @Override
    public void start() {

    }


    @Override
    public void getHomeData() {
        mModel.getHomeData().compose(mView.bindToLife()).subscribe(new Observer<HomeBo>() {
            @Override
            public void onSubscribe(Disposable d) {
                mView.showLoading(d);
            }

            @Override
            public void onNext(HomeBo homeBo) {
                mView.dismissLoading();
                mView.showSuccess(homeBo);
            }

            @Override
            public void onError(Throwable e) {
                mView.dismissLoading();
                mView.showError(e.getMessage());
            }

            @Override
            public void onComplete() {
                mView.dismissLoading();
            }
        });

    }
}
